import { CHANGE_USER_INFO } from "./constant";
import { getUserById } from "@/services";

const changeUserInfoAction = (data) => ({
  type: CHANGE_USER_INFO,
  data,
});

export const setUserInfoAction = (data) => {
  return (dispatch) => {
    dispatch(changeUserInfoAction(data));
  };
};

export const setNewUserInfoAction = (userId) => {
  return (dispatch) => {
    getUserById(userId).then((res) => {
      const userInfo = Object.assign(res, { isLogin: true });
      dispatch(changeUserInfoAction(userInfo));
    });
  };
};
